package com.yukefms.message;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author Ping
 * @Date 2021/6/24 23:38
 **/
/*@Component
@Slf4j*/
public class MessageHandler {


  //  @KafkaListener(topics = KafkaConfig.TOPIC_TEST, containerFactory = "ackContainerFactory")
    public void handleMessage(ConsumerRecord record, Acknowledgment acknowledgment) {
        try {
            String message = (String) record.value();
            System.out.println("收到消息: " + message);
        } catch (Exception e) {
//            System.err(e.getMessage(), e);
        } finally {
            // 手动提交 offset
            acknowledgment.acknowledge();
        }
    }
}